<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title><? echo $title ?></title>
    <? require("lib.php"); ?>
    <link rel="stylesheet" href="css/jquery.datetimepicker.css" type="text/css" media="screen" />
    <script type="text/javascript" src="js/jquery.datetimepicker.js"></script>
</head>
<body>
<div class="content-box"><!-- Start Content Box -->
    <div class="content-box-header">
        <h3><? echo $title ?></h3>
        <div class="clear"></div>
    </div> <!-- End .content-box-header -->
    <div class="content-box-content">
        <?
        switch ($do) {
            case "add":
                add();
                break;
            case "update":
                update($info);
                break;
            case "delete":
                delete($id);
                break;
            default:
                show_info($info);
        }
        ?>
        <? function show_box($row, $iseditmode, $isadd=0){
            global $id, $h, $url, $title, $sales_promotion, $baseurl, $option, $lang, $code_array, $promotion_id, $sales_promotion_list;
            $full = isset($row['full']) ? $row['full'] : '';
            $cut = isset($row['cut']) ? $row['cut'] : '';
            $type = isset($row['type']) ? $row['type'] : 0;
            $arr_cate=$code_array['discount_type'];
        ?>
        <table width="99%" cellspacing="0" cellpadding="3" class="mbox">
            <tr class="th"><td class="thtitle" width="120" align="right"><? echo $title ?></td>
                <td><? if(isset($row['id'])) echo $h->hidden('id', iso($row["id"])); ?></td></tr>
            <tr><td class="l"><?=ROOT_SALES_PROMOTION_TOTAL?></td><td><? echo $h->text('full', $full, 'g') ?></td></tr>
            <tr><td class="l"><?=ROOT_SALES_PROMOTION_TYPE?></td><td><? echo $h->select('type', $type, $arr_cate, 'id', 'name_'.$lang, 'g'); ?></td></tr>
            <tr><td class="l"><?=ROOT_SALES_PROMOTION_CUT?></td><td><? echo $h->text('cut', $cut, 'g') ?></td></tr>
            <tr><td class="l">&nbsp;</td><td><br><? echo $h->submit('save', '&nbsp; '.ROOT_SAVE.' &nbsp;', $iseditmode==1?'':'hide') ?>&nbsp;&nbsp;<a onClick="history.go(-1)">[ <?=ROOT_CANCEL?> ]</a><br><br></td></tr>
        </table>
        <? } ?>
        <? function show_boxes($result){
            global $url, $page, $pages, $cateid, $s, $lang, $arrlang, $filter, $h, $code_array, $promotion_id, $promotion_name, $sales_promotion_list;
            $str='<table width="99%" cellspacing="0" class="mlist"><tr class="th"><td><strong>ID</strong></td><td><strong>'.ROOT_SALES_PROMOTION_TOTAL.'</strong></td><td>'.ROOT_SALES_PROMOTION_TYPE.'</td><td><strong>'.ROOT_SALES_PROMOTION_CUT.'</strong></td><td><a href="'.$url.'.php?do=add&promotion_id='.$promotion_id.'">[ '.ROOT_ADD.' ]</a></td></tr>';
            $count=1;
            $arr_cate=$code_array['discount_type'];
            foreach( $result as $row)
            {
                $id=$row['id'];
                $full = $row['full'];
                $cut = $row['cut'];
                if($promotion_id == 0){
                    $promotion_name = $sales_promotion_list->get_row($row['promotion_id']);
                }
                $type=$arr_cate[$row['type']]['name_'.$lang];
                $str.="<tr><td>".$id."</td><td>".$full."</td><td>".$type."</td><td>".$cut."</td><td><a href=\"$url.php?do=update&id=".$id."&promotion_id=".$promotion_id."\">".ROOT_UPDATE."</a> | <a href=\"$url.php?do=delete&id=".$id."&promotion_id=".$promotion_id."\" onClick=\"javascript: return delc();\">".ROOT_DELETE."</a></td></tr>";
                $count++;
            }
            $str.= "</table>";
            echo $str;
            if($count==1) echo "<br>No data now. (".ROOT_NO_DATA."!)";
            echo echo_page($page, $pages, $url.'-'.$cateid.'-p');
        } ?>
        <br class="clear" />
    </div> <!-- End .content-box-content -->
    <br class="clear" />
</div><!-- End .content-box -->
</body>
</html>
